import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)
        self.label=QLabel('Result')
        layout.addWidget(self.label)
        
        btn=QPushButton('ShowAbout')
        btn.clicked.connect(self.ShowAbout)
        layout.addWidget(btn)

        btn=QPushButton('ShowCritical')
        btn.clicked.connect(self.ShowCritical)
        layout.addWidget(btn)

        btn=QPushButton('ShowInformation')
        btn.clicked.connect(self.ShowInformation)
        layout.addWidget(btn)

        btn=QPushButton('ShowQuestion')
        btn.clicked.connect(self.ShowQuestion)
        layout.addWidget(btn)

        btn=QPushButton('ShowWarning')
        btn.clicked.connect(self.ShowWarning)
        layout.addWidget(btn)

        btn=QPushButton('ShowCustomInformation')
        btn.clicked.connect(self.ShowCustomInformation)
        layout.addWidget(btn)

        self.setLayout(layout)
    def ShowAbout(self):
        result= QMessageBox.about(self,'About','This is Demo')
        self.label.setText(f"Result:{result}") 
    def ShowCritical(self):
        result=QMessageBox.critical(self,'Critical','ShowCritical',QMessageBox.StandardButton.Yes,QMessageBox.StandardButton.No)
        self.label.setText(f"Result:{result}") 
    def ShowInformation(self):
        result=QMessageBox.information(self,'Information','ShowInformation',QMessageBox.StandardButton.Ok)
        self.label.setText(f"Result:{result}")
    def ShowQuestion(self):
        result=QMessageBox.question(self,'Question','ShowQuestion',QMessageBox.StandardButton.Yes,QMessageBox.StandardButton.No)
        self.label.setText(f"Result:{result}")
    def ShowWarning(self):
        result=QMessageBox.warning(self,'Warning','ShowWarning',QMessageBox.StandardButton.Apply,QMessageBox.StandardButton.Ignore)
        self.label.setText(f"Result:{result}")
    def ShowCustomInformation(self):
        msg=QMessageBox(self)
        msg.setWindowTitle('Information')
        msg.setInformativeText('Information Context')
        msg.setDetailedText('Information Detail')
        msg.setStandardButtons(QMessageBox.StandardButton.Save|QMessageBox.StandardButton.Ignore|QMessageBox.StandardButton.Cancel)
        msg.setDefaultButton(QMessageBox.StandardButton.Save)
        msg.setIcon(QMessageBox.Icon.Information)

        btn=QPushButton('CustmButton')
        btn.clicked.connect(msg.done(500))
        msg.addButton(btn,QMessageBox.ButtonRole.NoRole)
        result=msg.exec()
        
        self.label.setText(f"Result:{result}")
        if msg.clickedButton()==btn:
            self.label.setText(self.label.text()+f"\n CustomButton Clicked")
def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet